#include "No7pch.h"
#include "WindowsInput.h"
#include "No7/Core/Application.h"

#include <GLFW/glfw3.h>

nmspc::Input* nmspc::Input::input_instance = new nmspc::WindowsInput();

bool nmspc::WindowsInput::checkKeyPressedImpl(int key_code)
{
	auto window = static_cast<GLFWwindow*>(nmspc::Application::get().getWindow().getNativeWindow());
	auto state = glfwGetKey(window, key_code);
	return state == GLFW_PRESS || state == GLFW_REPEAT;
}

bool nmspc::WindowsInput::checkMouseButtonPressedImpl(int button)
{
	auto window = static_cast<GLFWwindow*>(nmspc::Application::get().getWindow().getNativeWindow());
	auto state = glfwGetMouseButton(window, button);
	return state == GLFW_PRESS;
}

std::pair<float, float> nmspc::WindowsInput::getMousePositionImpl()
{
	auto window = static_cast<GLFWwindow*>(nmspc::Application::get().getWindow().getNativeWindow());
	double x, y;
	glfwGetCursorPos(window, &x, &y);
	return { (float)x,(float)y };
}

float nmspc::WindowsInput::getMouseXImpl()
{
	auto [x, y] = this->getMousePosition();
	return x;
}

float nmspc::WindowsInput::getMouseYImpl()
{
	auto [x, y] = this->getMousePosition();
	return y;
}
